Skip to content

fix: Prevent early loan impairment and due-date manipulation#6557

Open
Tapanito wants to merge 1 commit into
tapanito/lending-fix-amendmentfrom
tapanito/lending-impairment
Open

fix: Prevent early loan impairment and due-date manipulation#6557
Tapanito wants to merge 1 commit into
tapanito/lending-fix-amendmentfrom
tapanito/lending-impairment

Conversation

@Tapanito
Copy link
Copy Markdown
Collaborator

Stop impairLoan and unimpairLoan from rewriting
sfNextPaymentDueDate when the amendment is active. Previously a colluding broker could repeatedly impair and unimpair an overdue loan to keep pushing the due date forward, permanently blocking default eligibility and suppressing late-interest / late-fee accrual.

spec: XRPLF/XRPL-Standards#496

High Level Overview of Change

Context of Change

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@Tapanito Tapanito requested review from a1q123456 and ximinez March 17, 2026 15:23
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.5%. Comparing base (68e4fbd) to head (810ffde).

Files with missing lines Patch % Lines
.../libxrpl/tx/transactors/lending/LendingHelpers.cpp 80.0% 1 Missing ⚠️
src/libxrpl/tx/transactors/lending/LoanManage.cpp 93.8% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##           tapanito/lending-fix-amendment   #6557   +/-   ##
==============================================================
  Coverage                            81.5%   81.5%           
==============================================================
  Files                                 999     999           
  Lines                               74550   74557    +7     
  Branches                             7560    7558    -2     
==============================================================
+ Hits                                60722   60731    +9     
+ Misses                              13828   13826    -2     
Files with missing lines Coverage Δ
...clude/xrpl/tx/transactors/lending/LendingHelpers.h 95.2% <ø> (ø)
.../libxrpl/tx/transactors/lending/LendingHelpers.cpp 88.5% <80.0%> (+<0.1%) ⬆️
src/libxrpl/tx/transactors/lending/LoanManage.cpp 92.2% <93.8%> (+2.1%) ⬆️

... and 1 file with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

Stop impairLoan and unimpairLoan from rewriting
sfNextPaymentDueDate when the amendment is active. Previously a
colluding broker could repeatedly impair and unimpair an overdue
loan to keep pushing the due date forward, permanently blocking
default eligibility and suppressing late-interest / late-fee
accrual.
- name: Upload coverage report
if: ${{ github.repository == 'XRPLF/rippled' && !inputs.build_only && env.COVERAGE_ENABLED == 'true' }}
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.5.3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed? I think we should open a separate PR if we want to update the version

@Tapanito Tapanito force-pushed the tapanito/lending-impairment branch from 971d16b to 810ffde Compare March 31, 2026 11:41
@github-actions
Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three logic issues flagged inline: missing precondition in computeLatePayment, a duplicate isPaymentLate call, and a post-unimpair state bug that enables immediate re-impairment under featureLendingProtocolV1_1.


Review by ReviewBot 🤖

Review by Claude Opus 4.6 · Prompt: V12

@@ -675,11 +681,6 @@ computeLatePayment(
TenthBips16 managementFeeRate,
beast::Journal j)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computeLatePayment lacks its own timing guard — any future caller bypasses tecTOO_SOON enforcement. Restore the precondition check inside the function:

// -------------------------------------------------------------
// A late payment not flagged as late overrides all other options.
if (paymentType != LoanPaymentType::late && hasExpired(view, nextDueDateProxy))
if (paymentType != LoanPaymentType::late && isPaymentLate(view, loan))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPaymentLate called twice on the same SLE — cache the result to avoid future TOCTOU-style divergence:

    bool const isLate = isPaymentLate(view, loan);
    if (paymentType != LoanPaymentType::late && isLate)

auto const normalPaymentDueDate =
std::max(loanSle->at(sfPreviousPaymentDueDate), loanSle->at(sfStartDate)) + paymentInterval;
if (!hasExpired(view, normalPaymentDueDate))
if (!view.rules().enabled(featureLendingProtocolV1_1))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unimpairLoan under featureLendingProtocolV1_1 skips advancing sfNextPaymentDueDate, leaving the loan perpetually late and re-impairable immediately. Advance the due date after clearing the impaired flag:

@bthomee bthomee added this to the 3.2.0 milestone May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants